package com.gao.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
public class StreamTest {
    /*
            保留年龄大于等于24岁的，并将其存入map集合中，姓名为键，年龄为值
     */
    public static void main(String[] args) {
       List<String> list = new ArrayList<>() ;
       list.add("张三,23");
       list.add("赵四,24");
       list.add("王五,25");
         Map<String, String> collect = list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                String[] split = s.split(",");
                return Integer.parseInt(split[1]) >= 24;
            }
        }).collect(Collectors.toMap(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.split(",")[0];
            }
        }, new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.split(",")[1];
            }
        }));
        System.out.println(collect);
    }
}
